/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.araujogrosz.fractalcore;

import java.awt.image.BufferedImage;

/**
 *
 * @author renatogrosz@gmail.com
 */
class ImagePainter implements FractalPrinter {

    private BufferedImage buf;
    private int startX, startY;
    private ColorMatrix colorMatrix;
    
    ImagePainter(int imageSize, ColorMatrix colorMatrix){
        buf = new BufferedImage(imageSize, imageSize, BufferedImage.TYPE_INT_RGB);        
        this.colorMatrix = colorMatrix;
        startX = 0;
        startY = 0;
    }
    
    ImagePainter(BufferedImage buf, ColorMatrix colorMatrix){
        this.colorMatrix = colorMatrix;
        this.buf = buf;
    }
    
    public void setStart(int startX, int startY){
        this.startX = startX;
        this.startY = startY;
    }
    
    @Override
    public void paint(int iteration, int x, int y) {        
        buf.setRGB(startX + x, startY + y, colorMatrix.getIntColor(iteration));        
    }

    @Override
    public void paint(int x, int y) {
        buf.setRGB(startX + x, startY + y, 0);
    }

    @Override
    public void paint() {}

    @Override
    public void paintOut(int x, int y) {
        buf.setRGB(startX + x, startY + y, 0);
    }
    
    public BufferedImage getBuf(){
        return buf;
    }    
}
